package java_class_work.week08.internet.upfile;

import java.io.*;
import java.net.Socket;

/**
 * @Author Tiam
 * @Date 2022/11/1 14:23
 * @Description: 文件上传
 */
public class TcpClient {
    public static void main(String[] args) {
        try {
            Socket socket = new Socket("127.0.0.1", 8888);
            // 读取文件
            BufferedReader bufferedReader = new BufferedReader(new FileReader(new File(".\\src\\java_class_work\\iotest\\output.txt")));

            PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
            BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));

            // DataOutputStream dataOutputStream = new DataOutputStream(socket.getOutputStream());
            // long time = System.currentTimeMillis();
            // dataOutputStream.write((int) time);

            String line = null;
            while ((line=bufferedReader.readLine())!=null){
                // 上传
                out.println(line);
            }
            // 关闭输出
            socket.shutdownOutput();

            // out.println(time);

            // 获取服务端的上传结果.
            String res = in.readLine();
            System.out.println(res);

            bufferedReader.close();
            socket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
